package com.orange.adminapi.controller.shopCategory;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.service.shopCategory.ShopCategoryService;
import com.orange.core.pojo.BR;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.shopCategory.dto.ShopCategoryDTO;
import com.orange.core.pojo.entity.shopCategory.vo.ShopCategoryVO;
import com.orange.core.pojo.req.shopCategory.ShopCategoryReq;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>ClassName:ShopCategoryController</p>
 * <p>Description: 品牌商铺分类controller</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/5/24 15:38</p>
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/shopCategory")
public class ShopCategoryController {

    private final ShopCategoryService shopCategoryService;


    /**
     * 品牌商铺分类列表查询
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).SHOP_CATEGORY_LIST.permission.identifier)")
    @GetMapping("/list")
    public R<List<ShopCategoryVO>> list(){
        return R.ok(shopCategoryService.shopCategoryList());
    }

    /**
     * 品牌商铺分类分页查询
     * @param pageReqDto
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).SHOP_CATEGORY_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<ShopCategoryVO>>  page(@RequestBody PageReqDto<ShopCategoryReq> pageReqDto){
        Page<ShopCategoryVO> page = shopCategoryService.page(pageReqDto);
        return R.ok(page);
    }

    /**
     * 品牌商铺分类详情
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).SHOP_CATEGORY_INFO.permission.identifier)")
    @GetMapping("/info/{id}")
    public R<ShopCategoryVO>  info(@PathVariable("id") Integer id){
        return R.ok(shopCategoryService.info(id));
    }

    /**
     * 品牌商铺分类新增
     * @param shopCategoryDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).SHOP_CATEGORY_SAVE.permission.identifier)")
    @PostMapping
    public R<Boolean> save(@RequestBody @Validated ShopCategoryDTO shopCategoryDTO){
        return BR.result(shopCategoryService.save(shopCategoryDTO));
    }

    /**
     * 品牌商铺分类修改
     * @param shopCategoryDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).SHOP_CATEGORY_UPDATE.permission.identifier)")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated ShopCategoryDTO shopCategoryDTO){
        return BR.result(shopCategoryService.update(shopCategoryDTO));
    }

    /**
     * 品牌商铺分类批量删除
     * @param ids
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).SHOP_CATEGORY_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove (@PathVariable Integer[] ids){
        return BR.result(shopCategoryService.deleteShopCategoryByIds(ids));
    }
}
